//Referencing input and output streams
#include<iostream.h>
int main()
{
//Defining the basic Identifiers
int hours,minutes;
int inthours,intminutes;
int total_time_minutes,total_time_hours;
int total_int_minutes,total_int_hours;
int total_minutes;
char opSymbol;
cout <<" Enter the time (h m): ";
cin >> hours >>minutes;
cout <<" Enter the interval (h m): ";
cin >> inthours >>intminutes;
cout <<" Enter the operation (+ or -): ";
cin >> opSymbol;
// Converting hours to minutes e.g. 2 hours* (60 miuntes / hour)
// for both time and interval entries.
total_time_minutes = hours*60 + minutes;
total_int_minutes = inthours*60 + intminutes;
//Implementing the switch operation here!!
switch (opSymbol)
{
case '+':
total_minutes = total_time_minutes + total_int_minutes;
break;
case '-':
total_minutes = total_time_minutes - total_int_minutes;
if(total_minutes<0)
{
total_minutes=total_minutes+24*60;
}
break;
default:
cout<< "Error! Operation should be + or - only "<<endl;
break;
}
cout<< " End time is: "<<total_minutes/60<<":"<<total_minutes%60
<<'\n';
return 0;
}
/*
Enter the time (h m): 7 15
Enter the interval (h m): 4 30
Enter the operation (+ or -): -
End time is: 2:45
Press any key to continue
*/
|